package com.facebook.android;

import java.io.InputStream;
import java.net.URL;

import android.content.Context;
import android.database.Cursor;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

public class MyImageAdapter extends BaseAdapter {
	private Context _context;
	private MyCache _cache;
	
	private String[] _urls = {
		"http://sphotos.ak.fbcdn.net/hphotos-ak-snc1/hs175.snc1/6570_110516463305_40796308305_2143765_6253354_n.jpg", 
		"http://sphotos.ak.fbcdn.net/hphotos-ak-snc1/hs175.snc1/6570_112530583305_40796308305_2172906_6022658_n.jpg", 
		"http://sphotos.ak.fbcdn.net/hphotos-ak-snc1/hs173.snc1/6490_115472073305_40796308305_2211192_2612642_n.jpg", 
		"http://sphotos.ak.fbcdn.net/hphotos-ak-snc1/hs173.snc1/6490_119653198305_40796308305_2265788_6171865_n.jpg", 
		"http://sphotos.ak.fbcdn.net/hphotos-ak-snc1/hs173.snc1/6490_121118198305_40796308305_2285112_3736116_n.jpg", 
		"http://sphotos.ak.fbcdn.net/hphotos-ak-snc1/hs145.snc1/5370_127826373305_40796308305_2373079_2781005_n.jpg", 
		"http://sphotos.ak.fbcdn.net/hphotos-ak-snc1/hs203.snc1/7026_130680503305_40796308305_2406802_2947273_n.jpg", 
		"http://sphotos.ak.fbcdn.net/hphotos-ak-snc3/hs165.snc3/19236_288392003305_40796308305_3332806_5262816_n.jpg", 
		"http://sphotos.ak.fbcdn.net/hphotos-ak-snc3/hs590.snc3/31122_392127513305_40796308305_3881652_2977202_n.jpg", 
		"http://sphotos.ak.fbcdn.net/hphotos-ak-snc3/hs573.snc3/31242_396265423305_40796308305_3964670_8144467_n.jpg", 
		"http://sphotos.ak.fbcdn.net/hphotos-ak-snc3/hs286.snc3/27942_396966058305_40796308305_3977819_6911115_n.jpg", 
		"http://sphotos.ak.fbcdn.net/hphotos-ak-snc3/hs639.snc3/32042_403062093305_40796308305_4124253_5779341_n.jpg"
	};
	
	public MyImageAdapter(Context context, MyCache cache) {
		_context = context;
		_cache = cache;
	}
	
	@Override
	public int getCount() {
		return _urls.length;
	}
	
	@Override
	public Object getItem(int position) {
        return position;
    }
	
	@Override
	public long getItemId(int position) {
        return position;
    }
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
        ImageView iv = new ImageView(_context);

        try {
	        URL url = new URL(_urls[position]);
	        iv.setImageDrawable(_cache.getImage(url, _context));
	        /*
	    	InputStream is = (InputStream) url.getContent();
	    	Drawable image = Drawable.createFromStream(is, "src");
			iv.setImageDrawable(image);
			*/
        } catch (Exception e) {
        	Log.d("averangeall", "error: " + e);
        }
		
        return iv;
    }
}
